package com.dream.keigezhushou.Activity.kege.acty;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.Uiutils.StringUtils;
import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.acty.ksong.ChorusInfoActivity;
import com.dream.keigezhushou.Activity.acty.ksong.KsongInfoActivity;
import com.dream.keigezhushou.Activity.acty.listen.myview.AlertDialog;
import com.dream.keigezhushou.Activity.kege.adapter.ChorusListAdapter;
import com.dream.keigezhushou.Activity.kege.adapter.RemoteMusicAdapter;
import com.dream.keigezhushou.R;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 已点
 */

public class RemoteMusicActivity extends AppCompatActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.list_lv)
    PullToRefreshListView mMPullToRefreshListView;
    private ListView mListlv;
    ArrayList<String> datalist;
    private RemoteMusicAdapter adapter;

    String state[] = {"合唱", "Ｋ歌", "Ｋ歌", "Ｋ歌", "合唱", "Ｋ歌", "合唱", "Ｋ歌", "合唱", "合唱", "Ｋ歌", "合唱", "合唱", "Ｋ歌", "Ｋ歌"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remote_music);
        ButterKnife.bind(this);
        initView();
        initClick();
    }

    //初始化控件
    public void initView() {
        tvTitle.setText("已点");
        mListlv = mMPullToRefreshListView.getRefreshableView();

        datalist = new ArrayList<>();

        for (int i = 0; i < state.length; i++) {
            datalist.add(state[i]);
        }

        adapter = new RemoteMusicAdapter(RemoteMusicActivity.this, datalist);
        mListlv.setAdapter(adapter);
        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
    //控件点击事件

    public void initClick() {
        adapter.setOnItemClickLinstener(new RemoteMusicAdapter.OnItemClickLinstener() {
            @Override
            public void onItemClick(int postion) {
                if (state.equals("Ｋ歌")) {

                    Intent intent = new Intent();
                    intent.putExtra(StringUtils.KEGESTATE, state);
                    intent.setClass(RemoteMusicActivity.this, SingingDetailActivity.class);
                    startActivity(intent);


                } else if (state.equals("合唱")) {
                    Intent intent = new Intent();
                    intent.putExtra(StringUtils.KEGESTATE, state);
                    intent.setClass(RemoteMusicActivity.this, SingingDetailActivity.class);
                    startActivity(intent);

                }
            }

            @Override
            public void onDetelClick(final int postion) {

                DisplayMetrics metric = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metric);
                int width = (int) (metric.widthPixels * 0.6);
//                    int height = (int) (metric.heightPixels);
                AlertDialog myalerdialog = new AlertDialog(View.inflate(RemoteMusicActivity.this, R.layout.alertdialog, null), RemoteMusicActivity.this, width, ViewGroup.LayoutParams.WRAP_CONTENT);
                myalerdialog.showPopAtLocation(mMPullToRefreshListView, Gravity.CENTER_HORIZONTAL);

                myalerdialog.setItemListener(new AlertDialog.ItemClickListener() {
                    @Override
                    public void onClick() {
                        adapter.removeItem(postion);
                        mListlv.setAdapter(adapter);

                    }


                });

            }

            @Override
            public void onSingStateClick(int postion, String state) {
                if (state.equals("Ｋ歌")) {

                    Intent intent = new Intent();
                    intent.putExtra(StringUtils.KEGESTATE, state);
                    intent.setClass(RemoteMusicActivity.this, ChorusInfoActivity.class);
                    startActivity(intent);


                } else if (state.equals("合唱")) {
                    Intent intent = new Intent();
                    intent.putExtra(StringUtils.KEGESTATE, state);
                    intent.setClass(RemoteMusicActivity.this, KsongInfoActivity.class);
                    startActivity(intent);

                }
            }
        });


    }


}
